import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base/17_Navigator_push_pop_route/route17.dart';

class Home16 extends StatefulWidget {
  const Home16({super.key});

  @override
  State<Home16> createState() => _Home16State();
}

class _Home16State extends State<Home16> with SingleTickerProviderStateMixin {
  late TabController _tabController;

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    print('*********** home 16销毁**************');
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print('*********** home 16 init**************');
    _tabController = TabController(length: 8, vsync: this);
    _tabController.addListener(() {
      if (_tabController.animation?.value == _tabController.index) {
        print(_tabController.index);
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          // 路由跳转到 Route17界面，并传值
          Navigator.of(context).push(MaterialPageRoute(builder: (context) {
            return const Route17();
          }));
        },
        heroTag: null, //'pushToRoute17',
        child: const Icon(Icons.add),
      ),
      appBar: PreferredSize(
        preferredSize: const Size.fromHeight(40),
        child: AppBar(
          elevation: 0.5,
          backgroundColor: Colors.white,
          title: SizedBox(
            height: 30,
            child: TabBar(
                // labelPadding: const EdgeInsets.only(left: 0),
                // indicatorPadding: const EdgeInsets.only(bottom: 5, left: 0),

                dragStartBehavior: DragStartBehavior.down,
                isScrollable: true,
                indicatorColor: Colors.orange,
                indicatorSize: TabBarIndicatorSize.label,
                labelColor: Colors.orange,
                labelStyle: const TextStyle(fontSize: 20),
                unselectedLabelStyle: const TextStyle(fontSize: 15),
                controller: _tabController,
                tabs: const [
                  Tab(
                    text: '首页',
                  ),
                  Tab(
                    text: '体育',
                  ),
                  Tab(
                    text: '热点',
                  ),
                  Tab(
                    text: '音乐',
                  ),
                  Tab(
                    text: '社会',
                  ),
                  Tab(
                    text: '游戏',
                  ),
                  Tab(
                    text: '222',
                  ),
                  Tab(
                    text: '333',
                  ),
                ]),
          ),
        ),
      ),
      body: TabBarView(controller: _tabController, children: const [
        Text('首页'),
        Text('体育'),
        Text('热点'),
        Text('音乐'),
        Text('社会'),
        Text('游戏'),
        Text('222'),
        Text('333'),
      ]),
    );
  }
}
